<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
	<title>汪卡测试页面</title>
	<link rel="stylesheet" href="/Public/node_modules/font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="/Public/style/ionic.min.css">
	<link rel="stylesheet" href="/Public/style/css/ionic-webapp.min.css">
	<link rel="stylesheet" href="/Public/node_modules/weui/dist/style/weui.min.css">
	<style>
		li.weui_uploader_file{width:150px;height: 120px;}
		li.weui_uploader_file>img{width:150px;height: 120px;}
		div.weui_uploader_input_wrp{ width: 120px; height: 120px;}
		.hidden{display:none}
	</style>
	<script type="text/javascript" src="/Public/javascript/ionic.bundle.min.js"></script>
	<script type="text/javascript" src="/Public/javascript/webapp/jsencrypt.min.js"></script>
	<script type="text/javascript">
		var wait=60;
		var baseUrl = 'http://www.wangka.cn/';
		var angularUrl = baseUrl + 'Service/angular.html';
		var templatePath = '/Public/template/Webapp/';
		angular.module('start', ['ionic', 'starter.services', 'starter.controllers'])
			.run(function($ionicPlatform) {
				$ionicPlatform.ready(function() {
					if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
						cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
						cordova.plugins.Keyboard.disableScroll(true);
					}
					if (window.StatusBar) {
						StatusBar.styleDefault();
					}
				});
			})
			.config(function($stateProvider, $urlRouterProvider,$ionicConfigProvider) {
			$ionicConfigProvider.platform.ios.tabs.style('standard');
			$ionicConfigProvider.platform.ios.tabs.position('bottom');
			$ionicConfigProvider.platform.android.tabs.style('standard');
			$ionicConfigProvider.platform.android.tabs.position('bottom');
			$ionicConfigProvider.platform.ios.navBar.alignTitle('center');
			$ionicConfigProvider.platform.android.navBar.alignTitle('center');
			$ionicConfigProvider.platform.ios.views.transition('ios');
			$ionicConfigProvider.platform.android.views.transition('ios');
			$stateProvider
				.state('tab', {
					url: '/tab',
					abstract: true,
					templateUrl: templatePath + 'tabs.html',
					controller: 'tabCtrl'
				})
				.state('tab.login', {
					url: '/login',
					cache: false,
					views: {
						'tab-home': {
							templateUrl: templatePath + 'logins.html',
							controller: 'loginCtrl'
						}
					}
				})
				.state('tab.home', {
					url: '/home',
					views: {
						'tab-home': {
							templateUrl: templatePath + 'home.html',
							controller: 'homec'
						}
					}
				});
			$urlRouterProvider.otherwise('/tab/login');
		});

		angular.module('starter.services', [])
			.factory('myService', function($http, $rootScope, $ionicLoading){
				function xhr(param, callback){
					$ionicLoading.show({content: 'Loading', animation: 'fade-in', showBackdrop: true, maxWidth: 200, showDelay: 0});
					if(param.ac != 'getBaseData'){
						var crypt = new JSEncrypt();
						crypt.setPublicKey($rootScope.rsa_key.public);
						var data = {ac: param.ac, op: param.op, mo: param.mo, rsa: crypt.encrypt(JSON.stringify(param))};
					}else{
						var data = param;
					}
					if(typeof(callback) != 'function'){
						return $http({
							url: angularUrl,
							method: "POST",
							headers: {'Content-Type': 'application/x-www-form-urlencoded'},
							data: data
						});
					}else{
						return $http({
							url: angularUrl,
							method: "POST",
							headers: {'Content-Type': 'application/x-www-form-urlencoded'},
							data: data
						}).success(function(resp){
							$ionicLoading.hide();
							callback(resp);
						});
					}
				}
				return {
					getBaseData: function(refresh){
						return xhr({ac: 'getBaseData', refresh: refresh}, function(resp){
							$rootScope.rsa_key = resp.rsa_key;
						});
					},
					login: function(param, callback){
						xhr(angular.extend({ac: 'login'}, param), function(resp){
							if(typeof(callback) != 'function') callback(resp);
						});
					}
				};
			})
			.factory('myPopup', function($ionicPopup){
				"弹出框服务";
				return {
					alert: function(param){
						"alert（警告） 对话框";
						switch(param.type){
							case 'success':
								var title = (typeof param.title == 'null')?'操作成功啦!':param.title;
								var icon = 'ion-checkmark-round';
								break;
							case 'error':
								var title = (typeof param.title == 'null')?'操作失败啦!':param.title;
								var icon = 'ion-close-round';
								break;
							default:
								var title = (typeof param.title == 'null')?'系统操作提示!':param.title;
								var icon = 'ion-information-circled';
								break;
						}
						return $ionicPopup.alert({
							title: title,
							template: '<div class="row"><div class="col col-25"><i class="icon '+icon+'"></i></div><div class="col col-75">'+param.content+'</div></div>'
						});
					}
				}
			});

		angular.module('starter.controllers', ['ionic'])
			.controller('tabCtrl', function(myService){
				myService.getBaseData(true);
			})
			.controller('loginCtrl', function($scope, $rootScope, $state, myPopup, myService){
				"用户登录控制器";
				$scope.verifyImg = baseUrl + '/App/verifyImg';
				$scope.login = {};
				$scope.refresh = function(){
					$scope.verifyImg = $scope.verifyImg + '?' + Math.random();
				}
				//console.log($rootScope);
				$scope.submit = function(){
					var post = angular.extend($scope.login, {op: 'login', rsa: true, return_rsa: true});
					myService.login(post, function(resp){
						myPopup.alert(resp);
						console.log(resp);
					});

					/*myService.login(post).success(function(resp){
						myPopup.alert(resp);
					})*/
				}
			})
	</script>
</head>
<body ng-app='start' class="bg-gray">
<ion-nav-bar class="bar-stable">
	<ion-nav-back-button class="button-clear"> <i class="icon ion-ios-arrow-back"></i>返回</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
<script id="login.html" type="text/ng-template">
	<ion-view view-title="登录" hide-tabs="true">
		<ion-nav-buttons side="right">
			<a class="button button-small button-clear button-stable" href="#/tab/register">注册 ></a>
		</ion-nav-buttons>
		<ion-content class="padding">
			<form name="theForm" novalidate="novalidate">
				<div class="list">
					<div class="row">
						<div class="col">
							<label class="item item-input">
								<span class="input-label">手机号码</span>
								<input type="text" name="mobile" ng-model="login.mobile" placeholder="请填写手机号码" required>
							</label>
						</div>
					</div>
					<div class="row">
						<div class="col">
							<label class="item item-input">
								<span class="input-label">登录密码</span>
								<input type="password" name="password" ng-model="login.password" placeholder="请填写登录密码" required>
							</label>
						</div>
					</div>
					<div class="row">
						<div class="col col-60">
							<label class="item item-input">
								<span class="input-label">图形验证码</span>
								<input type="tel" name="vdcode" ng-model="login.vdcode" placeholder="请填写验证码" required>
							</label>
						</div>
						<div class="col">

						</div>
					</div>
					<div class="row" ng-show="theForm.$invalid">
						<div class="col">
							<div class="card">
								<div class="item item-divider">注册表单错误提示</div>
								<div class="item item-text-wrap item-icon-left assertive" ng-show="theForm.mobile.$invalid && theForm.mobile.$error.required">
									<i class="icon ion-close-circled placeholder-icon"></i> 用户手机号码必须填写!
								</div>
								<div class="item item-text-wrap item-icon-left assertive" ng-show="theForm.password.$invalid && theForm.password.$error.required">
									<i class="icon ion-close-circled placeholder-icon"></i> 用户密码必须填写!
								</div>
								<div class="item item-text-wrap item-icon-left assertive" ng-show="theForm.vdcode.$invalid && theForm.vdcode.$error.required">
									<i class="icon ion-close-circled placeholder-icon"></i> 图形验证码必须填写!
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="list list-normal">
					<button class="button button-full button-energized" ng-click="submit()" ng-disabled="!theForm.$valid">登录</button>
				</div>
			</form>
		</ion-content>
	</ion-view>
</script>
<script id="tab.html" type="text/ng-template">
	<ion-tabs class="tabs-icon-top tabs-color-active-positive hhh" >
		<ion-tab title="汪卡" icon-off="ion-ios-home-outline" icon-on="ion-ios-home" ui-sref="app.tabs.home" ng-click='click(1)'>
			<ion-nav-view name="tab-home"></ion-nav-view>
		</ion-tab>
		<ion-tab title="账户" icon-off="ion-ios-pie-outline" icon-on="ion-ios-pie" href="#/app/tabs/account" ng-click='click(2)'>
			<ion-nav-view name="tab-account"></ion-nav-view>
		</ion-tab>
		<ion-tab title="发现" icon-off="ion-ios-world-outline" icon-on="ion-ios-world" href="#/app/tabs/discovery" ng-click='click(3)'>
			<ion-nav-view name="tab-discovery"></ion-nav-view>
		</ion-tab>
		<ion-tab title="个人中心" icon-off="ion-ios-person-outline" icon-on="ion-ios-person" href="#/app/tabs/my" ng-click='click(4)'>
			<ion-nav-view name="tab-my"></ion-nav-view>
		</ion-tab>
	</ion-tabs>
</script>
</body>
</html>